library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ tibble  3.1.0     ✓ purrr   0.3.4
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(arsenal)
library(data.table)
## 
## Attaching package: 'data.table'
## The following object is masked from 'package:purrr':
## 
##     transpose
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
library(expss)
## 
## Attaching package: 'expss'
## The following objects are masked from 'package:data.table':
## 
##     copy, like
## The following objects are masked from 'package:stringr':
## 
##     fixed, regex
## The following objects are masked from 'package:purrr':
## 
##     keep, modify, modify_if, transpose, when
## The following objects are masked from 'package:tidyr':
## 
##     contains, nest
## The following objects are masked from 'package:dplyr':
## 
##     between, compute, contains, first, last, na_if, recode, vars
## The following object is masked from 'package:ggplot2':
## 
##     vars
library(ggsci)

#ideas, stratify by what do you consider a good nights sleep
#additive index according to behaviors 
#regression models for the outcome.

#Positive quality of sleep - 
#Consistent wake up 
#Greater than 7 hrs to 9 hrs --> stratify #for sure USE THIS AND ONE OR THE OTHER
  #Agreement questions Q44
  #Current bedtime routines
  #Current lifestyle habits
  #Employment and children
analysisdata <- readRDS("foranalysis.rds")
#Binary variable for seven or nine weighted as 1
analysisdata <- analysisdata %>% mutate(
  sevenornine = case_when(
    Q10_workdayhoursofsleep >= 7.0 & Q10_workdayhoursofsleep <= 9.0 ~ 1,
    Q10_workdayhoursofsleep < 7.0 | Q10_workdayhoursofsleep > 9.0 ~ 0,
    is.na(Q10_workdayhoursofsleep) ~ NA_real_
    ))


#analysisdata <- analysisdata %>% mutate(
#  sevenornine = case_when(
#    Q10_workdayhoursofsleep >= 7.0 & Q10_workdayhoursofsleep <= 9.0 ~ 2,
#    Q10_workdayhoursofsleep < 7.0 | Q10_workdayhoursofsleep > 9.0 ~ 0,
#    is.na(Q10_workdayhoursofsleep) ~ NA_real_
#    ))

#Binary variable for quality of sleep weighted as 1
analysisdata <- analysisdata %>% mutate(
  quality = case_when(
    Q44_6_ifeelpositiveaboutthequalityofmysleep == "Somewhat agree" ~ 1,
    Q44_6_ifeelpositiveaboutthequalityofmysleep == "Strongly agree" ~ 1,
    is.na(Q44_6_ifeelpositiveaboutthequalityofmysleep) ~ NA_real_,
    TRUE ~ 0))

#Binary variable for consistency of wake up weighted as 1
analysisdata <- analysisdata %>% mutate(
  consistency = case_when(
    Q13_consistentwakeup == "Yes" ~ 1,
    is.na(Q13_consistentwakeup) ~ NA_real_,
    TRUE ~ 0))

#Compositescore computation
analysisdata <- analysisdata %>% mutate(
  compositescore = sevenornine + quality + consistency
  )

#analysisdata <- analysisdata %>% mutate(compositeoutcomegoodsleep = factor(compositescore, label = c("score 0 - worst sleep", "score 1", "score 2", "score 3 - best sleep"))) %>%
#  filter(!is.na(compositescore))

#analysisdata <- analysisdata %>% mutate(compositeoutcomegoodsleep = factor(compositescore, label = c("score 0 - worst sleep", "score 1", "score 2", "score 3", "score 4 - best sleep"))) %>%
#  filter(!is.na(compositescore))


 analysisdata <- analysisdata %>% mutate(compositeoutcomegoodsleep = case_when(
   compositescore >= 2 ~ 1,
   compositescore < 2 ~ 0,
   is.na(compositescore) ~ NA_real_)) %>% 
   mutate(compositeoutcomegoodsleep = factor(compositeoutcomegoodsleep, label = c("Poor sleep (score less than 2)", "Good sleep (score 2 or more)"))) %>%  filter(!is.na(compositescore))

#Logistic regression just input demographic variables, then add pyschosocial variables and see how that affects model statistics. Sequential adjustment.

#Cut it in different places. 
#Split between 2 and 3 , and 3 and 4 

#Cumulative score how many ones do you get 
#hours of sleep (7-9) vs. outside of (7-9) --> either interim category 
#quality of sleep (1) sometimes or (0)
#consistent wakeup (1) sometimes/no (0)
tab1 <- tableby(compositeoutcomegoodsleep~ Q3_role + 
                  Q4_gender +
                  Q5_age +
                  Q6_numberinhousehold +
                  Q37_employed +
                  Q8_diagnosis +
                  Q10_workdayhoursofsleep +
                  Q11_weekendhoursofsleep +
                  Q9_howoftensleepy,
                data=analysisdata, test=TRUE, total=TRUE, 
                numeric.stats=c("medianq1q3"), numeric.test="kwt", cat.test="chisq")
summary(tab1, title='Table 1. Baseline information', pfootnote=TRUE, digits = 2)
Table 1. Baseline information
Poor sleep (score less than 2) (N=91) Good sleep (score 2 or more) (N=107) Total (N=198) p value
What is your role at Bloomberg 0.8041
   Faculty/Staff Member 3 (3.3%) 2 (1.9%) 5 (2.5%)
   Full-time student 63 (69.2%) 74 (69.2%) 137 (69.2%)
   Part-time student 25 (27.5%) 31 (29.0%) 56 (28.3%)
What gender do you identify as? 0.0331
   Female 66 (72.5%) 92 (86.0%) 158 (79.8%)
   Male 20 (22.0%) 15 (14.0%) 35 (17.7%)
   Non-binary / third gender 4 (4.4%) 0 (0.0%) 4 (2.0%)
   Prefer not to say 1 (1.1%) 0 (0.0%) 1 (0.5%)
How old are you? 0.9832
   Median (Q1, Q3) 28.00 (25.00, 33.00) 28.00 (25.00, 31.50) 28.00 (25.00, 32.00)
How many people live in your household, including yourself? 0.0682
   Median (Q1, Q3) 2.00 (2.00, 3.00) 2.00 (2.00, 3.00) 2.00 (2.00, 3.00)
Are you currently employed outside of your education program? 0.1961
   N-Miss 1 0 1
   No 47 (52.2%) 46 (43.0%) 93 (47.2%)
   Yes 43 (47.8%) 61 (57.0%) 104 (52.8%)
Have you ever been diagnosed with any of the following sleep disorders? 0.8031
   Insomnia 7 (7.7%) 5 (4.7%) 12 (6.1%)
   No 81 (89.0%) 98 (91.6%) 179 (90.4%)
   Other 1 (1.1%) 2 (1.9%) 3 (1.5%)
   Sleep Apnea 2 (2.2%) 2 (1.9%) 4 (2.0%)
During the past 5 workdays, how many hours of sleep did you get per night on average? < 0.0012
   Median (Q1, Q3) 6.00 (5.00, 7.00) 7.00 (7.00, 8.00) 7.00 (6.00, 7.50)
During the past weekend, how many hours of sleep did you get per night on average? 0.0082
   Median (Q1, Q3) 7.50 (7.00, 9.00) 8.00 (7.50, 9.00) 8.00 (7.00, 9.00)
How often do you feel sleepy during the day?
   N-Miss 43 21 64
   Never 0 (0.0%) 2 (2.3%) 2 (1.5%)
   Rarely 7 (14.6%) 18 (20.9%) 25 (18.7%)
   Sometimes 33 (68.8%) 63 (73.3%) 96 (71.6%)
   Very often 0 (0.0%) 0 (0.0%) 0 (0.0%)
   Always 8 (16.7%) 3 (3.5%) 11 (8.2%)
  1. Pearson’s Chi-squared test
  2. Kruskal-Wallis rank sum test
#If student
student <- analysisdata %>% filter(Q3_role != "Faculty/Staff Member")

tab1 <- tableby(compositeoutcomegoodsleep~ Q2_program,
                data=student, test=TRUE, total=TRUE, 
                numeric.stats=c("medianq1q3"), numeric.test="kwt", cat.test="chisq")
summary(tab1, title='Table 1. Baseline information', pfootnote=TRUE, digits = 2)
Table 1. Baseline information
Poor sleep (score less than 2) (N=88) Good sleep (score 2 or more) (N=105) Total (N=193) p value
What is your current program at Bloomberg? 0.0961
   Doctoral Student 18 (20.5%) 34 (32.4%) 52 (26.9%)
   Masters Student 66 (75.0%) 69 (65.7%) 135 (69.9%)
   Other 0 (0.0%) 1 (1.0%) 1 (0.5%)
   Post doctoral student 4 (4.5%) 1 (1.0%) 5 (2.6%)
  1. Pearson’s Chi-squared test
#If employed 
employed <- analysisdata %>% filter(Q37_employed == "Yes")

tab1 <- tableby(compositeoutcomegoodsleep ~ Q38_wfh,
                data=employed, test=TRUE, total=TRUE, 
                numeric.stats=c("medianq1q3"), numeric.test="kwt", cat.test="chisq")
summary(tab1, title='Table 1. Baseline information', pfootnote=TRUE, digits = 2)
Table 1. Baseline information
Poor sleep (score less than 2) (N=43) Good sleep (score 2 or more) (N=61) Total (N=104) p value
Do you work from home? 0.4831
   No 14 (32.6%) 16 (26.2%) 30 (28.8%)
   Yes 29 (67.4%) 45 (73.8%) 74 (71.2%)
  1. Pearson’s Chi-squared test
#If wfh
notworkfromhome <- analysisdata %>% filter(Q37_employed == "Yes" & Q38_wfh == "No")

tab1 <- tableby(compositeoutcomegoodsleep ~ Q39_dayornight,
                data=notworkfromhome, test=TRUE, total=TRUE, 
                numeric.stats=c("medianq1q3"), numeric.test="kwt", cat.test="chisq")
summary(tab1, title='Table 1. Baseline information', pfootnote=TRUE, digits = 2)
Table 1. Baseline information
Poor sleep (score less than 2) (N=14) Good sleep (score 2 or more) (N=16) Total (N=30) p value
Do you work day or night shifts? 0.5011
   N-Miss 0 1 1
   Day shift 12 (85.7%) 14 (93.3%) 26 (89.7%)
   Night shift 2 (14.3%) 1 (6.7%) 3 (10.3%)
  1. Pearson’s Chi-squared test
tab1 <- tableby(compositeoutcomegoodsleep~  
                  Q15_consistentbedtimeonweekdays +
                  Q49_sleepqualitychangecovid +
                  bedtimeroutine +
                  Q19_howmanyhourssdidyouuseascreen +
                  as.numeric(Q19_howmanyhourssdidyouuseascreen) +
                  Q12_1_howmanynightsusescreen +
                  Q17_stressedaboutschool +
                  cantsleepfeeling +
                  Q18_howoftenpracticemindfullness +
                  behaviors +
                  Q44_1_thingsidointhelasthourbeforesleepaffectthequalityofmysleep +
                  Q44_2_gettingagoodnightssleepisimportantome +
                  Q44_3_mostofmyfriendshaveahealthysleeproutine +
                  Q44_4_lackofsleepaffectsmyacademicperformance +
                  Q44_5_havingaregularsleeproutineimprovesmentalclariy +
                  Q44_7_ithinkcuttingoutscreenuseonehourbeforesleepleadstobettersleep +
                  Q44_8_ithinkingworkingoutregularlyleadstobettersleep +
                  Q44_9_ithinkmeditatingbeforesleephelpsquality +
                  Q59_1_icanmaintainhealthysleephabits +
                  Q59_2_icancutoutscreenuseonehourbeforesleep +
                  Q59_3_icanworkoutregularly +
                  Q59_4_icanmediatebeforebed +
                  Q37_whatdoyouconsideragoodnightssleep +
                  Q50_1_energyfordailyacitivites +
                  Q50_2_attractivness +
                  Q50_3_productivity +
                  Q50_4_accomplishmentofotherdailygoals +
                  Q50_5_mentalandemotionalwellbeing +
                  Q50_6_fosteringmaintaingrelationships +
                  Q50_7_caringforchildren +
                  Q53_1_getoutsidefor10mininthemorning +
                  Q53_2_exerciseduringtheday +
                  Q53_3_doingabreathingexercisebeforesleep +
                  Q53_4_notusescreens +
                  Q53_5_listeningtoacalmingaudiobookorpodcast +
                  information,
                data=analysisdata, test=TRUE, total=TRUE, 
                numeric.stats=c("medianq1q3"), numeric.test="kwt", cat.test="chisq")
summary(tab1, title='Table 2. Sleep questions', pfootnote=TRUE, digits = 2)
Table 2. Sleep questions
Poor sleep (score less than 2) (N=91) Good sleep (score 2 or more) (N=107) Total (N=198) p value
Do you have a consistent time you wake up on weekdays? < 0.0011
   No 62 (68.1%) 23 (21.5%) 85 (42.9%)
   Sometimes 16 (17.6%) 31 (29.0%) 47 (23.7%)
   Yes 13 (14.3%) 53 (49.5%) 66 (33.3%)
Has your sleep quality changed due to the COVID-19 pandemic? < 0.0011
   N-Miss 1 1 2
   No 26 (28.9%) 44 (41.5%) 70 (35.7%)
   Yes, I feel my sleep quality has improved 4 (4.4%) 22 (20.8%) 26 (13.3%)
   Yes, I feel my sleep quality has worsened 60 (66.7%) 40 (37.7%) 100 (51.0%)
My bedtime routine includes: 0.6381
   N-Miss 1 0 1
   Brushing teeth 30 (33.3%) 33 (30.8%) 63 (32.0%)
   Phone usage 5 (5.6%) 4 (3.7%) 9 (4.6%)
   Reading 4 (4.4%) 1 (0.9%) 5 (2.5%)
   Showering 1 (1.1%) 1 (0.9%) 2 (1.0%)
   Washing my face 49 (54.4%) 67 (62.6%) 116 (58.9%)
   Watching TV 1 (1.1%) 1 (0.9%) 2 (1.0%)
How many hours per day do you typically use a screen? (i.e. cell phone, tablet, computer, television)
   N-Miss 2 1 3
   0 0 (0.0%) 0 (0.0%) 0 (0.0%)
   1 0 (0.0%) 0 (0.0%) 0 (0.0%)
   2 0 (0.0%) 0 (0.0%) 0 (0.0%)
   3 1 (1.1%) 2 (1.9%) 3 (1.5%)
   4 2 (2.2%) 3 (2.8%) 5 (2.6%)
   5 3 (3.4%) 2 (1.9%) 5 (2.6%)
   6 4 (4.5%) 5 (4.7%) 9 (4.6%)
   7 3 (3.4%) 2 (1.9%) 5 (2.6%)
   8 15 (16.9%) 11 (10.4%) 26 (13.3%)
   9 3 (3.4%) 7 (6.6%) 10 (5.1%)
   10 22 (24.7%) 33 (31.1%) 55 (28.2%)
   11 2 (2.2%) 0 (0.0%) 2 (1.0%)
   12 20 (22.5%) 29 (27.4%) 49 (25.1%)
   13 2 (2.2%) 2 (1.9%) 4 (2.1%)
   14 7 (7.9%) 6 (5.7%) 13 (6.7%)
   15 4 (4.5%) 1 (0.9%) 5 (2.6%)
   16 1 (1.1%) 2 (1.9%) 3 (1.5%)
   17 0 (0.0%) 1 (0.9%) 1 (0.5%)
How many hours per day do you typically use a screen? (i.e. cell phone, tablet, computer, television) 0.8922
   Median (Q1, Q3) 11.00 (9.00, 13.00) 11.00 (10.00, 13.00) 11.00 (9.00, 13.00)
In the past week, how many nights did you use screens (i.e. cell phone, tablet, computer, television) within 1 hour before bed? 0.3372
   Median (Q1, Q3) 7.00 (7.00, 7.00) 7.00 (6.00, 7.00) 7.00 (7.00, 7.00)
How stressed do you currently feel about school? 0.1822
   Median (Q1, Q3) 7.00 (6.00, 8.00) 7.00 (5.00, 8.00) 7.00 (5.75, 8.00)
When you can’t sleep do you feel 0.0301
   Angry 3 (3.3%) 8 (7.5%) 11 (5.6%)
   Frustrated 41 (45.1%) 59 (55.1%) 100 (50.5%)
   Guilty 23 (25.3%) 11 (10.3%) 34 (17.2%)
   None of the above 6 (6.6%) 7 (6.5%) 13 (6.6%)
   Other 5 (5.5%) 5 (4.7%) 10 (5.1%)
   Sad 5 (5.5%) 1 (0.9%) 6 (3.0%)
   Stressed 8 (8.8%) 16 (15.0%) 24 (12.1%)
How often do you practice mindfulness techniques? (i.e. breathing exercises, meditation, etc.,)
   N-Miss 8 10 18
   Never 12 (14.5%) 21 (21.6%) 33 (18.3%)
   Rarely 39 (47.0%) 34 (35.1%) 73 (40.6%)
   Sometimes 31 (37.3%) 39 (40.2%) 70 (38.9%)
   Very often 0 (0.0%) 0 (0.0%) 0 (0.0%)
   Always 1 (1.2%) 3 (3.1%) 4 (2.2%)
Which of the following behaviors do you participate in? 0.0841
   N-Miss 1 1 2
   Alcohol Consumption 36 (40.0%) 59 (55.7%) 95 (48.5%)
   Cigarette smoking 3 (3.3%) 1 (0.9%) 4 (2.0%)
   Daytime napping 0 (0.0%) 1 (0.9%) 1 (0.5%)
   Drinking Caffeinated beverages 2 (2.2%) 2 (1.9%) 4 (2.0%)
   Exercise 32 (35.6%) 35 (33.0%) 67 (34.2%)
   Social Media Use 17 (18.9%) 8 (7.5%) 25 (12.8%)
The things I do in the last hour before bed affect the quality of my sleep. 0.9001
   Strongly disagree 3 (3.3%) 3 (2.8%) 6 (3.0%)
   Somewhat disagree 5 (5.5%) 8 (7.5%) 13 (6.6%)
   Neither agree nor disagree 10 (11.0%) 8 (7.5%) 18 (9.1%)
   Somewhat agree 42 (46.2%) 52 (48.6%) 94 (47.5%)
   Strongly agree 31 (34.1%) 36 (33.6%) 67 (33.8%)
Getting a good night’s sleep is important to me. 0.0231
   Strongly disagree 0 (0.0%) 1 (0.9%) 1 (0.5%)
   Somewhat disagree 1 (1.1%) 0 (0.0%) 1 (0.5%)
   Neither agree nor disagree 3 (3.3%) 1 (0.9%) 4 (2.0%)
   Somewhat agree 19 (20.9%) 8 (7.5%) 27 (13.6%)
   Strongly agree 68 (74.7%) 97 (90.7%) 165 (83.3%)
Most of my friends have a healthy sleep routine. 0.1681
   N-Miss 1 0 1
   Strongly disagree 6 (6.7%) 3 (2.8%) 9 (4.6%)
   Somewhat disagree 21 (23.3%) 19 (17.8%) 40 (20.3%)
   Neither agree nor disagree 35 (38.9%) 60 (56.1%) 95 (48.2%)
   Somewhat agree 22 (24.4%) 20 (18.7%) 42 (21.3%)
   Strongly agree 6 (6.7%) 5 (4.7%) 11 (5.6%)
Lack of sleep affects my academic performance. 0.8941
   N-Miss 1 0 1
   Strongly disagree 1 (1.1%) 2 (1.9%) 3 (1.5%)
   Somewhat disagree 4 (4.4%) 7 (6.5%) 11 (5.6%)
   Neither agree nor disagree 7 (7.8%) 7 (6.5%) 14 (7.1%)
   Somewhat agree 39 (43.3%) 41 (38.3%) 80 (40.6%)
   Strongly agree 39 (43.3%) 50 (46.7%) 89 (45.2%)
Having a regular sleep routine improves mental clarity/sharpness.
   Strongly disagree 0 (0.0%) 0 (0.0%) 0 (0.0%)
   Somewhat disagree 1 (1.1%) 0 (0.0%) 1 (0.5%)
   Neither agree nor disagree 5 (5.5%) 5 (4.7%) 10 (5.1%)
   Somewhat agree 21 (23.1%) 29 (27.1%) 50 (25.3%)
   Strongly agree 64 (70.3%) 73 (68.2%) 137 (69.2%)
I think cutting out screen use 1 hour before bed leads to better sleep. 0.9221
   Strongly disagree 4 (4.4%) 3 (2.8%) 7 (3.5%)
   Somewhat disagree 2 (2.2%) 4 (3.7%) 6 (3.0%)
   Neither agree nor disagree 19 (20.9%) 20 (18.7%) 39 (19.7%)
   Somewhat agree 37 (40.7%) 46 (43.0%) 83 (41.9%)
   Strongly agree 29 (31.9%) 34 (31.8%) 63 (31.8%)
I think working out regularly leads to better sleep.
   Strongly disagree 0 (0.0%) 0 (0.0%) 0 (0.0%)
   Somewhat disagree 2 (2.2%) 1 (0.9%) 3 (1.5%)
   Neither agree nor disagree 8 (8.8%) 9 (8.4%) 17 (8.6%)
   Somewhat agree 29 (31.9%) 28 (26.2%) 57 (28.8%)
   Strongly agree 52 (57.1%) 69 (64.5%) 121 (61.1%)
I think meditating before bed helps sleep quality. 0.8941
   N-Miss 0 1 1
   Strongly disagree 4 (4.4%) 2 (1.9%) 6 (3.0%)
   Somewhat disagree 5 (5.5%) 6 (5.7%) 11 (5.6%)
   Neither agree nor disagree 30 (33.0%) 36 (34.0%) 66 (33.5%)
   Somewhat agree 29 (31.9%) 36 (34.0%) 65 (33.0%)
   Strongly agree 23 (25.3%) 26 (24.5%) 49 (24.9%)
I can maintain healthy sleep habits. < 0.0011
   N-Miss 1 0 1
   Not at all confident 12 (13.3%) 2 (1.9%) 14 (7.1%)
   Slightly confident 22 (24.4%) 6 (5.6%) 28 (14.2%)
   Somewhat confident 35 (38.9%) 30 (28.0%) 65 (33.0%)
   Pretty confident 20 (22.2%) 49 (45.8%) 69 (35.0%)
   Extremely confident 1 (1.1%) 20 (18.7%) 21 (10.7%)
I can cut out screen use 1 hour before bed. 0.0441
   N-Miss 1 0 1
   Not at all confident 19 (21.1%) 25 (23.4%) 44 (22.3%)
   Slightly confident 38 (42.2%) 24 (22.4%) 62 (31.5%)
   Somewhat confident 18 (20.0%) 32 (29.9%) 50 (25.4%)
   Pretty confident 9 (10.0%) 18 (16.8%) 27 (13.7%)
   Extremely confident 6 (6.7%) 8 (7.5%) 14 (7.1%)
I can work out regularly. 0.0281
   N-Miss 2 0 2
   Not at all confident 12 (13.5%) 3 (2.8%) 15 (7.7%)
   Slightly confident 17 (19.1%) 20 (18.7%) 37 (18.9%)
   Somewhat confident 15 (16.9%) 23 (21.5%) 38 (19.4%)
   Pretty confident 25 (28.1%) 24 (22.4%) 49 (25.0%)
   Extremely confident 20 (22.5%) 37 (34.6%) 57 (29.1%)
I can meditate before bed. 0.5691
   N-Miss 1 0 1
   Not at all confident 18 (20.0%) 26 (24.3%) 44 (22.3%)
   Slightly confident 27 (30.0%) 24 (22.4%) 51 (25.9%)
   Somewhat confident 26 (28.9%) 28 (26.2%) 54 (27.4%)
   Pretty confident 11 (12.2%) 20 (18.7%) 31 (15.7%)
   Extremely confident 8 (8.9%) 9 (8.4%) 17 (8.6%)
What do you consider a good night’s sleep? 0.2861
   10+ hours 1 (1.1%) 0 (0.0%) 1 (0.5%)
   7 hours 16 (17.6%) 11 (10.3%) 27 (13.6%)
   8 hours 58 (63.7%) 79 (73.8%) 137 (69.2%)
   9 hours 15 (16.5%) 17 (15.9%) 32 (16.2%)
   Less than or equal to 6 hours 1 (1.1%) 0 (0.0%) 1 (0.5%)
Energy for daily activities 0.2452
   Median (Q1, Q3) 5.00 (4.00, 5.00) 5.00 (4.00, 5.00) 5.00 (4.00, 5.00)
Attractiveness (to self & others) 0.2562
   Median (Q1, Q3) 3.00 (2.25, 4.00) 3.00 (2.00, 4.00) 3.00 (2.00, 4.00)
Productivity at work/school 0.9782
   Median (Q1, Q3) 5.00 (4.00, 5.00) 5.00 (4.00, 5.00) 5.00 (4.00, 5.00)
Accomplishment of other daily goals (e.g. exercise, cooking, paying bills, etc) 0.6932
   Median (Q1, Q3) 5.00 (4.00, 5.00) 4.00 (4.00, 5.00) 5.00 (4.00, 5.00)
Mental and emotional wellbeing 0.5032
   Median (Q1, Q3) 5.00 (4.00, 5.00) 5.00 (4.00, 5.00) 5.00 (4.00, 5.00)
Fostering/maintaining relationships 0.7842
   Median (Q1, Q3) 4.00 (3.00, 5.00) 4.00 (3.00, 5.00) 4.00 (3.00, 5.00)
Caring for children 0.9162
   Median (Q1, Q3) 1.00 (1.00, 3.00) 1.00 (1.00, 4.00) 1.00 (1.00, 3.00)
Get outside for 10 minutes in the morning. 0.7992
   Median (Q1, Q3) 4.00 (2.00, 5.00) 4.00 (2.00, 5.00) 4.00 (2.00, 5.00)
Exercise during the day. 0.0512
   Median (Q1, Q3) 4.00 (3.00, 5.00) 4.00 (3.00, 5.00) 4.00 (3.00, 5.00)
Do a breathing exercise before you sleep. 0.4692
   Median (Q1, Q3) 3.00 (2.00, 4.00) 3.00 (2.00, 4.00) 3.00 (2.00, 4.00)
Not use screens (i.e. cell phone, tablet, computer, television) for 1 hour before bed 0.0762
   Median (Q1, Q3) 2.00 (1.00, 3.00) 3.00 (2.00, 3.00) 2.00 (2.00, 3.00)
Listen to a calming audiobook or podcast before bed 0.8552
   Median (Q1, Q3) 3.00 (2.00, 4.00) 3.00 (2.00, 4.00) 3.00 (2.00, 4.00)
Where have you seen or received information about sleep quality or sleep hygiene? 0.0411
   N-Miss 7 8 15
   Friends 1 (1.2%) 7 (7.1%) 8 (4.4%)
   Health care professional 37 (44.0%) 33 (33.3%) 70 (38.3%)
   News sources 4 (4.8%) 8 (8.1%) 12 (6.6%)
   Other online source 12 (14.3%) 12 (12.1%) 24 (13.1%)
   Social media 20 (23.8%) 35 (35.4%) 55 (30.1%)
   University wellbeing resources 10 (11.9%) 4 (4.0%) 14 (7.7%)
  1. Pearson’s Chi-squared test
  2. Kruskal-Wallis rank sum test

Fig 1

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q3_role, fill=compositeoutcomegoodsleep)) +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=32)) +
  labs(title = "Role") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 2

g<- ggplot(student) + 
  geom_bar(aes(x=Q2_program, fill=compositeoutcomegoodsleep)) +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=32)) +
  labs(title = "What is your current program at Bloomberg?") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 3

g<- ggplot(student) + 
  geom_bar(aes(x=Q4_gender, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=32)) +
  labs(title = "What gender do you identify as?") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 4

g<- ggplot(student) + 
  geom_bar(aes(x=Q37_employed, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=32)) +
  labs(title = "Are you currently employed outside of your education program?") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 5

g<- ggplot(employed) + 
  geom_bar(aes(x=Q38_wfh, fill=compositeoutcomegoodsleep)) +
  coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=32)) +
  labs(title = "Do you work from home?") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 6

g<- ggplot(notworkfromhome) + 
  geom_bar(aes(x=Q39_dayornight, fill=compositeoutcomegoodsleep)) +
  coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=32)) +
  labs(title = "Do you work day or night shifts?") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 7

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q7_children, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=15)) +
  labs(title = "Are there children living in your household?") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 8

g<-ggplot(analysisdata) + 
  geom_bar(aes(x=Q8_diagnosis, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=20), axis.text.x = element_text(size=32)) +
  labs(title = "Have you ever been diagnosed with any of the following sleep disorders?") +
  xlab("") + 
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 9

g<-ggplot(analysisdata) + 
  geom_bar(aes(x=Q9_howoftensleepy, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=32)) +
  labs(title = "How often do you feel sleepy during the day?") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 10

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q13_consistentwakeup, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=32)) +
  labs(title = "Do you have a consistent time you wake up on weekdays?") +
  xlab("") + 
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 11

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q15_consistentbedtimeonweekdays, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Do you have a consistent bedtime on weekdays?") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 12

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q49_sleepqualitychangecovid, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Has your sleep quality changed due to the COVID-19 pandemic?") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 13

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=bedtimeroutine, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "My bedtime routine includes") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 14

g<-ggplot(analysisdata) + 
  geom_bar(aes(x=Q17_stressedaboutschool, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "How stressed do you currently feel about school?") +
  xlab("") + 
  labs(fill='') 

g+ scale_fill_lancet() 
## Warning: Removed 2 rows containing non-finite values (stat_count).

Fig 15

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=cantsleepfeeling, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "When you can't sleep do you feel") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 16

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q18_howoftenpracticemindfullness, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "How often do you practice mindfulness techniques? (i.e. breathing exercises, meditation, etc.,") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 17

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=behaviors, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Which of the following behaviors do you participate in? Check all that apply. ") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 18

g<-ggplot(analysisdata) + 
  geom_bar(aes(x=Q44_1_thingsidointhelasthourbeforesleepaffectthequalityofmysleep, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "The things I do in the last hour before bed affect the quality of my sleep.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q44_2_gettingagoodnightssleepisimportantome, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Getting a good night's sleep is important to me.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q44_3_mostofmyfriendshaveahealthysleeproutine, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Most of my friends have a healthy sleep routine.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q44_4_lackofsleepaffectsmyacademicperformance, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Lack of sleep affects my academic performance.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q44_5_havingaregularsleeproutineimprovesmentalclariy, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Having a regular sleep routine improves mental clarity/sharpness.") +
  xlab("") +
  labs(fill='') 
g+ scale_fill_lancet() 

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q44_6_ifeelpositiveaboutthequalityofmysleep, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I feel positive about the quality of my sleep.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q44_7_ithinkcuttingoutscreenuseonehourbeforesleepleadstobettersleep, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I think cutting out screen use 1 hour before bed leads to better sleep.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

g<-ggplot(analysisdata) + 
  geom_bar(aes(x=Q44_8_ithinkingworkingoutregularlyleadstobettersleep, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I think working out regularly leads to better sleep.") +
  xlab("") +
  labs(fill='') 
g+ scale_fill_lancet() 

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q44_9_ithinkmeditatingbeforesleephelpsquality, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I think meditating before bed helps sleep quality.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 19

g <- ggplot(analysisdata) + 
  geom_bar(aes(x=Q59_1_icanmaintainhealthysleephabits, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I can maintain healthy sleep habits.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q59_2_icancutoutscreenuseonehourbeforesleep, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I can cut out screen use 1 hour before bed.") +
  xlab("") +
  labs(fill='') 
g+ scale_fill_lancet() 

g <- ggplot(analysisdata) + 
  geom_bar(aes(x=Q59_3_icanworkoutregularly, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I can work out regularly.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q59_4_icanmediatebeforebed, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I can meditate before bed.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 20

g <- ggplot(analysisdata) + 
  geom_bar(aes(x=Q50_1_energyfordailyacitivites, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Energy for daily activities") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 
## Warning: Removed 1 rows containing non-finite values (stat_count).

g <- ggplot(analysisdata) + 
  geom_bar(aes(x=Q50_2_attractivness, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Attractiveness (to self & others)") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 
## Warning: Removed 1 rows containing non-finite values (stat_count).

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q50_3_productivity, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Productivity at work/school") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 
## Warning: Removed 1 rows containing non-finite values (stat_count).

g <- ggplot(analysisdata) + 
  geom_bar(aes(x=Q50_4_accomplishmentofotherdailygoals, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Accomplishment of other daily goals (e.g. exercise, cooking, paying bills, etc)") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 
## Warning: Removed 1 rows containing non-finite values (stat_count).

g<- ggplot(analysisdata) + 
  geom_bar(aes(x=Q50_5_mentalandemotionalwellbeing, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Mental and emotional wellbeing") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 
## Warning: Removed 2 rows containing non-finite values (stat_count).

g <- ggplot(analysisdata) + 
  geom_bar(aes(x=Q50_6_fosteringmaintaingrelationships, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Fostering/maintaining relationships") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 
## Warning: Removed 2 rows containing non-finite values (stat_count).

g <- ggplot(analysisdata) + 
  geom_bar(aes(x=Q50_7_caringforchildren, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "Caring for children") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 
## Warning: Removed 8 rows containing non-finite values (stat_count).

Fig 21

g <- ggplot(analysisdata) + 
  geom_bar(aes(x=Q59_1_icanmaintainhealthysleephabits, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I can maintain healthy sleep habits.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

g <- ggplot(analysisdata) + 
  geom_bar(aes(x=Q59_2_icancutoutscreenuseonehourbeforesleep, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I can cut out screen use 1 hour before bed.") +
  xlab("") +
  labs(fill='')  

g+ scale_fill_lancet() 

g<-ggplot(analysisdata) + 
  geom_bar(aes(x=Q59_3_icanworkoutregularly, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I can work out regularly.") +
  xlab("") +
  labs(fill='') 

g + scale_fill_lancet() 

g <-ggplot(analysisdata) + 
  geom_bar(aes(x=Q59_4_icanmediatebeforebed, fill=compositeoutcomegoodsleep)) +
  #coord_flip() +
  theme_test() +
  theme(text = element_text(size=32), axis.text.x = element_text(size=18)) +
  labs(title = "I can meditate before bed.") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet() 

Fig 22

g<-ggplot(analysisdata) + 
  geom_bar(aes(x=information, fill=compositeoutcomegoodsleep)) +
  theme_test() +
  theme(text = element_text(size=20), axis.text.x = element_text(size=16)) +
  labs(title = "Where have you seen or received information about sleep quality or sleep hygiene? Check all that apply. ") +
  xlab("") +
  labs(fill='') 

g+ scale_fill_lancet()